def merge_srt(file_path):
    with open(file_path, "r", encoding="utf-8") as f:
        lines = f.read().splitlines()
    texts = []
    i = 0
    while i < len(lines):
        if lines[i].strip():  # 跳过空行（遇到序号行）
            i += 2  # 跳过序号和时间戳行，指向第一条文本行
            text_lines = []
            while i < len(lines) and lines[i].strip():
                text_lines.append(lines[i].strip())
                i += 1
            texts.extend(text_lines)  # 合并文本行到列表
        else:
            i += 1  # 跳过空行分隔符

    # 按7行分段，段间空行
    result = []
    for i in range(0, len(texts), 7):
        segment = "\n".join(texts[i:i+7])
        result.append(segment)
    return "\n\n".join(result)  # 返回合并结果


# 使用示例：
file_path = r"C:\Users\Administrator\Videos\4月17日(1).srt"
print(merge_srt(file_path))
with open('asd2.txt', "w", encoding="utf-8") as f:
    f.write(merge_srt(file_path))
